<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	pageContext.setAttribute("path", path);
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
	pageContext.setAttribute("basePath", basePath);
%>
<!DOCTYPE html>
<html lang="en">

<head>
<title>小优智校</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="${path}/static/common/login/css/global.css" />	
<link rel="stylesheet" href="${path}/static/common/login/css/login.css" />
<script type="text/javascript" src="${path}/static/jquery/jquery-2.2.2.min.js"></script>
</head>
<body>
	<div id="login-content">
		<div id="login-logo">
			<div id="img-logo">
				<h1>小优智校</h1>
				<%-- <img src="${path}/static/common/login/image/login-logo.png"> --%>
			</div>
			<h1><%-- <img src="${path}/static/common/login/image/text.png"> --%></h1>
		</div>
		<div id="login-wrap">
			<div id="login-form">
				<form>
					<div id="loginbox" class="login-box">
						<div class="item">
							<input id="loginname" class="itxt" name="loginname" placeholder="用户名" type="text">
							<label class="login-label name-label"></label>
						</div>
						<div class="item">
							<input id="password" class="itxt itxt-error" name="password" placeholder="密码" type="password">
							<label class="login-label pwd-label"></label>
						</div>
						<!-- <div class="item">
							<input id="code" class="itxt itxt-error" name="code" placeholder="验证码" type="Captcha">
							<label class="login-label code-label">
								<img id="codeImg" alt="点击更换" title="点击更换" src="">
							</label>
						</div> -->
						<div class="item item-fore">
							<div class="login-btn">
								<a id="loginsubmit" class="btn-style btn-entry" href="###" onclick="severCheck();">登录</a>
								<a id="logincancel" class="btn-style btn-cancel" href="###" onclick="quxiao();">取消</a>
							</div>
						</div>
					</div>
				</form>
			</div>
		</div>
		<footer>
		<div id="login-footer">
			<p>Copyright  医路畅通患者随访系统   2017</p>
		</div>
	</footer>
	</div>
	<script type="text/javascript">
		//服务器校验
		function severCheck(){
			if(check()){
				var loginname = $("#loginname").val();
				var password = $("#password").val();
				var code = "29fed1ab318e4a18bc10c40f9d101627"+loginname+",sys,"+password+"19fed1ab318e4a18bc10c40f9d101626"+",sys,"+$("#code").val();
				$.ajax({
					type: "POST",
					url: '${path}/login_login',
			    	data: {KEYDATA:code,tm:new Date().getTime()},
					dataType:'json',
					cache: false,
					success: function(data){
						if("success" == data.result){
							window.location.href="${path}/main/index";
						}else if("usererror" == data.result){
							$("#loginname").tips({
								side : 1,
								msg : "用户名或密码有误",
								bg : '#FF5080',
								time : 15
							});
							$("#loginname").focus();
						}else if("codeerror" == data.result){
							$("#code").tips({
								side : 1,
								msg : "验证码输入有误",
								bg : '#FF5080',
								time : 15
							});
							$("#code").focus();
						}else{
							$("#loginname").tips({
								side : 1,
								msg : "缺少参数",
								bg : '#FF5080',
								time : 15
							});
							$("#loginname").focus();
						}
					}
				});
			}
		}
	
		$(document).ready(function() {
			changeCode();
			$("#codeImg").bind("click", changeCode);
		});

		$(document).keyup(function(event) {
			if (event.keyCode == 13) {
				$("#loginsubmit").trigger("click");
			}
		});

		function genTimestamp() {
			var time = new Date();
			return time.getTime();
		}
		function changeCode() {
			$("#codeImg").attr("src", "${path}/code.do?t=" + genTimestamp());
		}
		//客户端校验
		function check() {
			if ($("#loginname").val() == "") {
				$("#loginname").tips({
					side : 2,
					msg : '用户名不得为空',
					bg : '#AE81FF',
					time : 3
				});

				$("#loginname").focus();
				return false;
			} else {
				$("#loginname").val(jQuery.trim($('#loginname').val()));
			}

			if ($("#password").val() == "") {

				$("#password").tips({
					side : 2,
					msg : '密码不得为空',
					bg : '#AE81FF',
					time : 3
				});

				$("#password").focus();
				return false;
			}
			if ($("#code").val() == "") {

				$("#code").tips({
					side : 1,
					msg : '验证码不得为空',
					bg : '#AE81FF',
					time : 3
				});

				$("#code").focus();
				return false;
			}

			$("#loginbox").tips({
				side : 1,
				msg : '正在登录 , 请稍后 ...',
				bg : '#68B500',
				time : 10
			});

			return true;
		}
		function quxiao() {
			$("#loginname").val('');
			$("#password").val('');
		}
	</script>
	<script>
		//TOCMAT重启之后 点击左侧列表跳转登录首页 
		if (window != top) {
			top.location.href = location.href;
		}
	</script>
	<script type="text/javascript" src="${path}/static/common/platform/js/jquery.tips.js"></script>
</body>
</html>